to Dynamic Percent Px
EN Converts a Number (base Dp value) into a dynamically scaled pixel Float for View-based (non-Compose) code.
The scaling logic:
Builds a 64-bit packed cache key from all dimension parameters.
If enableCache is
true(default): checks DimenCache first. On a hit, returns the cached pixel value immediately. On a miss, calls calculatePercentDp and converts Dp→px viascaledDp * displayMetrics.density(equivalent to android.util.TypedValue.applyDimension forCOMPLEX_UNIT_DIP), then stores the result.If enableCache is
false: computes directly via calculatePercentDp, bypassing cache.
⚠️ Bypass note: when applyAspectRatio is
falseand qualifier isSMALL_WIDTHwithDEFAULTinverter, the DimenCache.getOrPut call internally bypasses the hash lookup because a raw multiply (~2 ns) is faster than the cache access (~5 ns). Calls with these parameters measure raw math performance, NOT cache throughput.
Bulk resolution: for many keys in one pass, prefer building LongArray keys with DimenCache.buildKey and DimenCache.getBatch. Early init: call DimenSdp.warmupCache (or DimenSsp.warmupCache) once with your android.content.Context so persistence/DataStore work does not land on the first hot-frame call.
PT Converte um Number (valor Dp base) em um Float em pixels dinamicamente escalado para código View-based.
A lógica de escalonamento:
Constrói uma chave de cache de 64 bits a partir de todos os parâmetros da dimensão.
Se enableCache for
true(padrão): consulta o DimenCache primeiro. No acerto, retorna o valor em pixels cacheado; no miss, calcula via calculatePercentDp e armazena.Se enableCache for
false: calcula diretamente via calculatePercentDp.
Return
Dynamically scaled pixel value as Float.
Parameters
Android android.content.Context for configuration and density access.
Orientation-based dimension swap rule (default: Inverter.DEFAULT).
If true, returns the base value in pixels unscaled when in split-screen.
If true, applies the aspect-ratio multiplier.
Override for the AR sensitivity constant (null = library default).